Page({
  data: {
    goodsId: null,
    goodsInfo: null,
    rateList: [
      {
        id: 1,
        username: '张三',
        content: '服务很好，阿姨很专业',
        rating: 5,
        date: '2024-03-20'
      },
      {
        id: 2,
        username: '李四',
        content: '打扫得很干净，很满意',
        rating: 5,
        date: '2024-03-19'
      }
    ],
    serviceStaff: [
      {
        id: 1,
        name: '王小倩',
        title: '专注于家政清洁服务，具有八年工作经验，曾获得"最佳服务员工"称号',
        avatar: '/static/zhyl/护理师1.png',
        rating: 5.0
      },
      {
        id: 2,
        name: '李阿姨',
        title: '专注于家政清洁服务，具有五年工作经验',
        avatar: '/static/zhyl/护理师2.png',
        rating: 4.9
      }
    ]
  },

  onLoad: function(options) {
    console.log('详情页接收到的参数:', options);
    
    // 商品信息假数据
    const goodsInfoMap = {
      1: {
        id: 'KF174194004243589',
        gname: '日常保洁',
        price: 199,
        sales: 1000,
        prove: '/static/images/cleaning1.png',
        description: '专业的保洁服务，让您的家焕然一新'
      },
      2: {
        id: 'KF174194004243587',
        gname: '深度保洁',
        price: 299,
        sales: 800,
        prove: '/static/images/cleaning1.png',
        description: '深度清洁，彻底除尘除垢'
      },
      3: {
        id: 'KF174194004243588',
        gname: '除螨服务',
        price: 399,
        sales: 600,
        prove: '/static/images/cleaning1.png',
        description: '专业除螨，还您健康睡眠'
      }
    };

    // 获取商品ID并转换为数字
    let goodsId = parseInt(options.id);
    if (isNaN(goodsId)) {
      goodsId = 1; // 如果转换失败，默认使用ID为1的商品
    }
    
    // 设置商品信息
    const goodsInfo = goodsInfoMap[goodsId] || goodsInfoMap[1];
    this.setData({
      goodsId: goodsInfo.id, // 使用字符串类型的ID
      goodsInfo: goodsInfo
    });
    
    console.log('设置的商品ID:', goodsInfo.id);
    console.log('设置的商品信息:', goodsInfo);
  },

  // 返回上一页
  goBack: function() {
    wx.navigateBack();
  },

  // 立即购买
  buyNow: function() {
    console.log('点击立即购买，当前商品ID:', this.data.goodsId);
    
    // 检查商品ID是否有效
    if (!this.data.goodsId || !this.data.goodsInfo) {
      wx.showToast({
        title: '商品信息错误',
        icon: 'none'
      });
      return;
    }

    // 跳转到预约页面
    wx.navigateTo({
      url: '/pages/services/homecare/booking/index?goodsId=' + this.data.goodsId
    });
  },

  // 加入购物车
  addToCart: function() {
    wx.showToast({
      title: '已加入购物车',
      icon: 'success'
    });
  },

  // 查看更多评价
  viewMoreRates: function() {
    wx.navigateTo({
      url: `/pages/comment/comment?goodsId=${this.data.goodsId}`
    });
  }
}); 